package menu

import (
	"go-zero-project/common/global"
	"go-zero-project/common/response"
	"go-zero-project/common/validator"
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"go-zero-project/services/user/api/internal/logic/menu"
	"go-zero-project/services/user/api/internal/svc"
	"go-zero-project/services/user/api/internal/types"
)

func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.DeleteMenuReq
		if err := httpx.Parse(r, &req); err != nil {
			response.Response(w, nil, err)
			return
		}
		// 参数校验
		if err := validator.Validate(r.Context(), req, global.ZH); err != nil {
			response.Response(w, nil, err)
			return
		}
		l := menu.NewDeleteMenuLogic(r.Context(), svcCtx)
		err := l.DeleteMenu(&req)
		response.Response(w, nil, err)
	}
}
